﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Agency_Tra_No_No_change : System.Web.UI.Page
{
    static string strSql, GoodsId, projectid;
   static int ProductId ;
    protected void Page_Load(object sender, EventArgs e)
    {
        GoodsId = SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["GoodsId"]));
        projectid = SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["projectid"]));
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            if (!IsPostBack)
            {
                Db db = new Db();
                System.Data.IDataReader dr;
                strSql = "select * from Bid_goods_product_cs_tb_agent where GoodsID=" + GoodsId + " and projectid=" + projectid;
                dr = db.DataReader(strSql);
                while (dr.Read())
                {
                    labgoodscode.Text = dr["GoodsId"].ToString();
                    labgoodname.Text = dr["GoodsName"].ToString();
                    labType.Text=dr["Medicinemodel"].ToString();
                    labProductname.Text = dr["ProductName"].ToString();
                    laboutlook.Text = dr["Outlookc"].ToString();
                    Labunit.Text = dr["Unit"].ToString();
                    Labpack.Text = dr["Pack"].ToString();
                    Labfactor.Text = dr["Factor"].ToString();
                    LabCompanyName_SC.Text = dr["CompanyName_SC"].ToString();
                    LabPackUnit.Text=SysFun.ToTrim(dr["PackUnit"]);
                    txtCompanyName_PS.Text = "请选择配送企业";
                    rdoQualityLevels.SelectedValue = SysFun.ToTrim(dr["QualityLevels"]);
                    BidPrice.Text= dr["bidprice"].ToString();
                  
                }
                dr.Close();
                dr.Dispose();
                db.Close();
            }
        }     
    }
    protected void Button2_ServerClick(object sender, EventArgs e) //添加到总配送目录表
    {
        if (txtCompanyName_PS.Text.Contains("请选择配送企业")==true)
        {
            Response.Write("<script>alert('您还没有选择配送企业，不能添加！');</script>");
        }
        else
        {
            Db db = new Db();
            System.Data.IDataReader dr;
            strSql = "select * from Bid_goods_product_cs_tb_agent where GoodsID=" + GoodsId + " and projectid=" + projectid;
            dr = db.DataReader(strSql);
            dr.Read();
            strSql = "insert into SupplyPlan_Goods values(" + projectid + "," + ProductId + ",'" + labProductname.Text + "','" + labType.Text + "','" + laboutlook.Text + "','" +
                      Labunit.Text + "','" + SysFun.ToTrim(dr["ProductCode"]) + "','"+SysFun.ToTrim(dr["BidTableName"])+"','"+SysFun.ToTrim(dr["BidTableType"])+"','"+SysFun.ToTrim(dr["BidTableOutlookc"])+"','" + labgoodscode.Text + "','" + labgoodname.Text + "'," + rdoQualityLevels.SelectedValue + ",'" + Labpack.Text + "'," +
                       Labfactor.Text + ",'" + LabPackUnit.Text + "'," + SysFun.ToInt(dr["AccountId_SC"]) + ",'" + LabCompanyName_SC.Text + "','" + SysFun.ToTrim(dr["UserCode_SC"]) + "'," + SysFun.ToInt(dr["AccountId_Agent"]) + ",'" + SysFun.ToTrim(dr["companyName_Agent"]) + "'," + SysFun.ToInt(dr["AccountId_TB"]) + ",'" + SysFun.ToTrim(dr["CompanyName_TB"]) + "','" + SysFun.ToTrim(dr["UserCode_TB"]) + "'," +
                       txtAccountId_PS.Value + ",'" + txtCompanyName_PS.Text + "','" + TextPs_UserCode.Text + "','" + BidPrice.Text + "',null,1,2,null,null," + Convert.ToInt32(dr["FrontSortId"]) + ",'" + SysFun.ToTrim(dr["FrontSortName"]) + "'," +SysFun.ToInt(dr["SortId"]) + ",'"
                       + SysFun.ToTrim(dr["SortName"]) + "',null,null,null,null,null,null,'a','a',0,'" +SysFun.ToTrim(dr["SpellingCode"]) + "')";
            dr.Close();
            db.Command(strSql);
            dr.Close();
            dr.Dispose();
            db.Close();
            Response.Write(@"<script language='javascript'>alert('添加成功！2秒钟后页面将自动关闭');setTimeout('self.close()',2000);</script>");
            Response.Write(@"<script lannguage='javascript'>window.opener.location.href='Tra_NoComp_NoLimit_goods.aspx?projectid=" + projectid + "'</script>");

        }

    }
  
}
